package order.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.AllArgsConstructor;
import order.dto.AddNutrition;
import order.dto.FoodNutrition;
import order.mapper.FoodNutritionMapper;
import org.apache.dubbo.config.annotation.DubboService;

import java.util.List;
@AllArgsConstructor
@DubboService(version = "1.0.0")
public class FoodNutritionImpl implements FoodNutritionI {
    FoodNutritionMapper foodNutritionMapper;
    public List<FoodNutrition> getAllFoodNutriton(){

        return foodNutritionMapper.selectList(null);
    }
    public FoodNutrition getFoodNutritionById(int id){
        LambdaQueryWrapper<FoodNutrition> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(FoodNutrition::getId,id);
        return foodNutritionMapper.selectOne(queryWrapper);
    }
    public FoodNutrition CalcuFoodNutrition(AddNutrition addNutrition){
        FoodNutrition foodNutrition = getFoodNutritionById(addNutrition.getId());
        foodNutrition.setEnergy(foodNutrition.getEnergy()*addNutrition.getQuality());
        foodNutrition.setProtein(foodNutrition.getProtein()*addNutrition.getQuality());
        foodNutrition.setFats(foodNutrition.getFats()*addNutrition.getQuality());
        foodNutrition.setCarbohydrate(foodNutrition.getCarbohydrate()*addNutrition.getQuality());
        return foodNutrition;
    }
}
